//
//  BaseViewController.m
//  JiaXiHeZi
//
//  Created by 郑信鸿 on 16/5/11.
//  Copyright © 2016年 郑信鸿. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"allbg"]];
    [self.view addSubview:backImageView];
    [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_offset(0);
        make.left.mas_offset(0);
        make.right.mas_offset(0);
        make.bottom.mas_offset(0);
        
    }];
    self.backImageView = backImageView;
    if ([[self.navigationController viewControllers] count] > 1) {
        [self resetBackBarButton];
    }
    
    self.view.backgroundColor = kBackgoundColor;
    // Do any additional setup after loading the view.
}

- (void)resetBackBarButton
{
    UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBarButton.frame = CGRectMake(0, 0, 60, 40);
    leftBarButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [leftBarButton setImage:[UIImage imageNamed:@"nav_icon_back"] forState:UIControlStateNormal];
    
    [leftBarButton addTarget:self action:@selector(viewWillBack) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];
    
}

-(void)viewWillBack
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)dealloc{
    
    NSLog(@"----%@---dealloc",NSStringFromClass([self class]));
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
